package cruncher;

import ilog.concert.IloNumVar;
import ilog.concert.cppimpl.IloIntVar;

import java.util.HashSet;
import java.util.Set;

public class Solution extends HashSet<Variable> implements Comparable<Solution> {

	public Solution(double objValue) {
		super();
		this.objValue = objValue;
	}
	
	
	private double objValue;
	private boolean isOptimal = false;

	public HashSet<Variable> getDecisionVariables() {
		HashSet<Variable> result = new HashSet<Variable>();
		for (Variable v : this)
		{
			if (v.isInteger())
			{
				result.add(v);
			}
			
		}
		return result;
	}

	public double getValue(Variable x) throws Exception {
		for (Variable v : this)
		{
			if (v.getName().equals(x.getName()))
				{
					return v.getValue();
				}	
		}
		throw new Exception("Can't find value");
	}

	public double getObjValue() {
		return objValue;
	}

	public void setObjValue(double objValue) {
		this.objValue = objValue;
	}

	public void setOptimal(boolean opt)
	{
		this.isOptimal = opt;
	}
	
	public boolean isOptimal()
	{
		return isOptimal;
	}

	@Override
	public int compareTo(Solution o) {
		if (this.objValue == o.objValue)
			return 0;
		else if (this.objValue < o.objValue)
			return -1;
		else
			return 1;
	}
}
